package com.atguigu.gmall.item.all.comtroller;

import com.atguigu.gmall.cart.client.CartFeignClient;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.client.ProductFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class CartController {

    @Autowired
    private CartFeignClient cartFeignClient;

    @Autowired
    private ProductFeignClient productFeignClient;

    //添加购物车的控制器
    @GetMapping("addCart.html")
    public String addCart(HttpServletRequest request){
        String skuId = request.getParameter("skuId");
        String skuNum = request.getParameter("skuNum");
        //调用添加购物车方法
        cartFeignClient.addToCart(Long.parseLong(skuId), Integer.parseInt(skuNum));
        SkuInfo skuInfo = productFeignClient.getSkuInfo(Long.parseLong(skuId));
        request.setAttribute("skuNum", skuNum);
        request.setAttribute("skuInfo", skuInfo);
        //返回页面
        return "cart/addCart";
    }

    //购物车列表页面
    @GetMapping("cart.html")
    public String cartList(){
        return "cart/index";
    }
}
